<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const obj = {
        name: 'zs',
        age: 18,
      }
      const data ={
        num: 1
      }
      Object.defineProperty(obj,'sex',{
        // value:'男',
        // writable: false, // 控制用defineProperty方法添加的属性能不能修改
        enumerable: true,//控制用defineProperty方法添加的属性能不能被遍历，（枚举）
        configurable: true,// 控制用defineProperty方法添加的属性能不能被删除
        get(){
          return data.num //将data.num和obj.sex双向关联
        },
        set(value){
          data.num = value//将data.num和obj.sex双向关联
        }
      })
      console.log(data.num);
      data.num = 2
      // obj.sex = '女'
      // delete obj.sex
      console.log(Object.keys(obj));
      console.log(obj);
      console.log(data.num);

      

    </script>
  </body>
</html>
